import 'package:flutter/material.dart';
import 'package:ymApp/pages/channel/channel.dart';
import 'package:ymApp/pages/news/news.dart';
import 'package:ymApp/pages/profile/profile.dart';
import 'pages/index/index.dart';

class MyMainScreen extends StatefulWidget {
  static String routeName = 'MyMainScreen';
  @override
  _MyMainScreenState createState() => _MyMainScreenState();
}

class _MyMainScreenState extends State<MyMainScreen> {
  int _currentIndex;
  List<Widget> tabPages;
  @override
  void initState() {
    super.initState();
    _currentIndex = 0;
    tabPages = [
      IndexPage(),
      ChannelPage(),
      News(),
      ProfilePage(),
    ];
  }

  @override
  Widget build(BuildContext context) {
    //  屏幕设备信息
    final width = MediaQuery.of(context).padding;

    return Scaffold(
//      body: this.tabPages[_currentIndex],
      body: IndexedStack(
        children: tabPages,
        index: _currentIndex,
      ),
      bottomNavigationBar: BottomNavigationBar(
        backgroundColor: Colors.red,
        fixedColor: Colors.red,
        unselectedItemColor: Colors.black45,
        currentIndex: _currentIndex,
        unselectedLabelStyle: TextStyle(color: Colors.black45, fontSize: 10),
        showUnselectedLabels: true,
        items: <BottomNavigationBarItem>[
          BottomNavigationBarItem(icon: Icon(Icons.home), title: Text('主页')),
          BottomNavigationBarItem(
              icon: Icon(Icons.open_with), title: Text('频道')),
          BottomNavigationBarItem(icon: Icon(Icons.people), title: Text('动态')),
          BottomNavigationBarItem(icon: Icon(Icons.people), title: Text('我的'))
        ],
        onTap: (idx) {
          setState(() {
            this._currentIndex = idx;
          });
        },
      ),
    );
  }
}
